package com.cooperate.fly.controller;
import com.cooperate.fly.service.buildDB.BuildCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/page")
public class PageController {

    @Autowired
    public BuildCaseService buildCaseService;
	//数据库数据项的定义
	@RequestMapping("/field")
	public String fieldDesign(){
		return "page/field-design";
	}

    @RequestMapping("/schema")
    public String schemaDesign(){
        return "schema-design";
    }

    @RequestMapping("/caseData-design/{id}")
    public String caseDataDesign(@PathVariable String id, Model model){
        int Id = Integer.parseInt(id);
        String caseFieldTree = buildCaseService.buildCaseFieldTree(Id);
        model.addAttribute("caseFieldData",caseFieldTree);
        model.addAttribute("caseId",Id);
        return "page/caseData-design";
    }

    @RequestMapping("/caseCatalog-design")
    public String caseCatalogDesign(){
        return "page/caseCatalog-design";
    }

    @RequestMapping("/showDataBaseCases/{dataBaseId}")
    public String showDataBaseCases(@PathVariable String dataBaseId, Model model){
        int id = Integer.parseInt(dataBaseId);
        String caseJson = buildCaseService.getDataBaseCases(id);
        model.addAttribute("caseJson", caseJson);
        model.addAttribute("dataBaseId",id);
        return "page/showDataBaseCases";
    }

    @RequestMapping("/showCatalogCases/{caseId}")
    public String showCatalogCases(@PathVariable String caseId, Model model){
        int id = Integer.parseInt(caseId);
        String caseJson = buildCaseService.getCatalogCases(id);
        model.addAttribute("caseJson", caseJson);
        model.addAttribute("catalogId",id);
        return "page/showCatalogCases";
    }



}
